List

interface List<out E> : Collection<E>

A generic ordered collection of elements. Methods in this interface support only read-only access to the list; read/write access is supported through the MutableList interface.

Parameters

E

the type of elements contained in the list. The list is covariant in its element type.

Functions

contains
Link copied to clipboard
abstract operator override fun contains(element: @UnsafeVariance E): Boolean
containsAll
Link copied to clipboard
abstract override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean
get
Link copied to clipboard
abstract operator fun get(index: Int): E

Returns the element at the specified index in the list.

indexOf
Link copied to clipboard
abstract fun indexOf(element: @UnsafeVariance E): Int

Returns the index of the first occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.

isEmpty
Link copied to clipboard
abstract override fun isEmpty(): Boolean
iterator
Link copied to clipboard
abstract operator override fun iterator(): Iterator<E>
lastIndexOf
Link copied to clipboard
abstract fun lastIndexOf(element: @UnsafeVariance E): Int

Returns the index of the last occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.

listIterator
Link copied to clipboard
abstract fun listIterator(): ListIterator<E>

Returns a list iterator over the elements in this list (in proper sequence).

abstract fun listIterator(index: Int): ListIterator<E>

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified index.

subList
Link copied to clipboard
abstract fun subList(fromIndex: Int, toIndex: Int): List<E>

Returns a view of the portion of this list between the specified fromIndex (inclusive) and toIndex (exclusive). The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.

Properties

size
Link copied to clipboard
abstract override val size: Int

Inheritors

AbstractList
Link copied to clipboard
MutableList
Link copied to clipboard

Extensions

asReversed
Link copied to clipboard
fun <T> List<T>.asReversed(): List<T>

Returns a reversed read-only view of the original List. All changes made in the original list will be reflected in the reversed one.

binarySearch
Link copied to clipboard
fun <T : Comparable<T>> List<T?>.binarySearch(element: T?, fromIndex: Int = 0, toIndex: Int = size): Int

Searches this list or its range for the provided element using the binary search algorithm. The list is expected to be sorted into ascending order according to the Comparable natural ordering of its elements, otherwise the result is undefined.

fun <T> List<T>.binarySearch(element: T, comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size): Int

Searches this list or its range for the provided element using the binary search algorithm. The list is expected to be sorted into ascending order according to the specified comparator, otherwise the result is undefined.

fun <T> List<T>.binarySearch(fromIndex: Int = 0, toIndex: Int = size, comparison: (T) -> Int): Int

Searches this list or its range for an element for which the given comparison function returns zero using the binary search algorithm.

binarySearchBy
Link copied to clipboard
inline fun <T, K : Comparable<K>> List<T>.binarySearchBy(key: K?, fromIndex: Int = 0, toIndex: Int = size, crossinline selector: (T) -> K?): Int

Searches this list or its range for an element having the key returned by the specified selector function equal to the provided key value using the binary search algorithm. The list is expected to be sorted into ascending order according to the Comparable natural ordering of keys of its elements. otherwise the result is undefined.

component1
Link copied to clipboard
inline operator fun <T> List<T>.component1(): T

Returns 1st element from the list.

component2
Link copied to clipboard
inline operator fun <T> List<T>.component2(): T

Returns 2nd element from the list.

component3
Link copied to clipboard
inline operator fun <T> List<T>.component3(): T

Returns 3rd element from the list.

component4
Link copied to clipboard
inline operator fun <T> List<T>.component4(): T

Returns 4th element from the list.

component5
Link copied to clipboard
inline operator fun <T> List<T>.component5(): T

Returns 5th element from the list.

dropLast
Link copied to clipboard
fun <T> List<T>.dropLast(n: Int): List<T>

Returns a list containing all elements except last n elements.

dropLastWhile
Link copied to clipboard
inline fun <T> List<T>.dropLastWhile(predicate: (T) -> Boolean): List<T>

Returns a list containing all elements except last elements that satisfy the given predicate.

elementAt
Link copied to clipboard
inline fun <T> List<T>.elementAt(index: Int): T

Returns an element at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this list.

elementAtOrElse
Link copied to clipboard
inline fun <T> List<T>.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T

Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this list.

elementAtOrNull
Link copied to clipboard
inline fun <T> List<T>.elementAtOrNull(index: Int): T?

Returns an element at the given index or null if the index is out of bounds of this list.

findLast
Link copied to clipboard
inline fun <T> List<T>.findLast(predicate: (T) -> Boolean): T?

Returns the last element matching the given predicate, or null if no such element was found.

first
Link copied to clipboard
fun <T> List<T>.first(): T

Returns first element.

firstOrNull
Link copied to clipboard
fun <T> List<T>.firstOrNull(): T?

Returns the first element, or null if the list is empty.

foldRight
Link copied to clipboard
inline fun <T, R> List<T>.foldRight(initial: R, operation: (T, R) -> R): R

Accumulates value starting with initial value and applying operation from right to left to each element and current accumulator value.

foldRightIndexed
Link copied to clipboard
inline fun <T, R> List<T>.foldRightIndexed(initial: R, operation: (index: Int, T, R) -> R): R

Accumulates value starting with initial value and applying operation from right to left to each element with its index in the original list and current accumulator value.

getOrElse
Link copied to clipboard
inline fun <T> List<T>.getOrElse(index: Int, defaultValue: (Int) -> T): T

Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this list.

getOrNull
Link copied to clipboard
fun <T> List<T>.getOrNull(index: Int): T?

Returns an element at the given index or null if the index is out of bounds of this list.

indexOf
Link copied to clipboard
fun <T> List<T>.indexOf(element: T): Int

Returns first index of element, or -1 if the list does not contain element.

indexOfFirst
Link copied to clipboard
inline fun <T> List<T>.indexOfFirst(predicate: (T) -> Boolean): Int

Returns index of the first element matching the given predicate, or -1 if the list does not contain such element.

indexOfLast
Link copied to clipboard
inline fun <T> List<T>.indexOfLast(predicate: (T) -> Boolean): Int

Returns index of the last element matching the given predicate, or -1 if the list does not contain such element.

last
Link copied to clipboard
fun <T> List<T>.last(): T

Returns the last element.

inline fun <T> List<T>.last(predicate: (T) -> Boolean): T

Returns the last element matching the given predicate.

lastIndex
Link copied to clipboard
val <T> List<T>.lastIndex: Int

Returns the index of the last item in the list or -1 if the list is empty.

lastIndexOf
Link copied to clipboard
fun <T> List<T>.lastIndexOf(element: T): Int

Returns last index of element, or -1 if the list does not contain element.

lastOrNull
Link copied to clipboard
fun <T> List<T>.lastOrNull(): T?

Returns the last element, or null if the list is empty.

inline fun <T> List<T>.lastOrNull(predicate: (T) -> Boolean): T?

Returns the last element matching the given predicate, or null if no such element was found.

orEmpty
Link copied to clipboard
inline fun <T> List<T>?.orEmpty(): List<T>

Returns this List if it's not null and the empty list otherwise.

reduceRight
Link copied to clipboard
inline fun <S, T : S> List<T>.reduceRight(operation: (T, S) -> S): S

Accumulates value starting with the last element and applying operation from right to left to each element and current accumulator value.

reduceRightIndexed
Link copied to clipboard
inline fun <S, T : S> List<T>.reduceRightIndexed(operation: (index: Int, T, S) -> S): S

Accumulates value starting with the last element and applying operation from right to left to each element with its index in the original list and current accumulator value.

reduceRightIndexedOrNull
Link copied to clipboard
inline fun <S, T : S> List<T>.reduceRightIndexedOrNull(operation: (index: Int, T, S) -> S): S?

Accumulates value starting with the last element and applying operation from right to left to each element with its index in the original list and current accumulator value.

reduceRightOrNull
Link copied to clipboard
inline fun <S, T : S> List<T>.reduceRightOrNull(operation: (T, S) -> S): S?

Accumulates value starting with the last element and applying operation from right to left to each element and current accumulator value.

requireNoNulls
Link copied to clipboard
fun <T : Any> List<T?>.requireNoNulls(): List<T>

Returns an original collection containing all the non-null elements, throwing an IllegalArgumentException if there are any null elements.

single
Link copied to clipboard
fun <T> List<T>.single(): T

Returns the single element, or throws an exception if the list is empty or has more than one element.

singleOrNull
Link copied to clipboard
fun <T> List<T>.singleOrNull(): T?

Returns single element, or null if the list is empty or has more than one element.

slice
Link copied to clipboard
fun <T> List<T>.slice(indices: IntRange): List<T>

Returns a list containing elements at indices in the specified indices range.

fun <T> List<T>.slice(indices: Iterable<Int>): List<T>

Returns a list containing elements at specified indices.

takeLast
Link copied to clipboard
fun <T> List<T>.takeLast(n: Int): List<T>

Returns a list containing last n elements.

takeLastWhile
Link copied to clipboard
inline fun <T> List<T>.takeLastWhile(predicate: (T) -> Boolean): List<T>

Returns a list containing last elements satisfying the given predicate.

toCStringArray
Link copied to clipboard
fun List<String>.toCStringArray(autofreeScope: AutofreeScope): CPointer<CPointerVar<ByteVar>>

Convert this list of Kotlin strings to C array of C strings, allocating memory for the array and C strings with given AutofreeScope.

toCValues
Link copied to clipboard
fun <T : CPointed> List<CPointer<T>?>.toCValues(): CValues<CPointerVar<T>>